/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package terminal.model;

import java.util.ArrayList;
import terminal.interfaces.IStringListener;

/**
 *
 * @author prpo4526
 */
public class SerialPortDataProcessor 
{
    public SerialPortDataProcessor()
    {
        m_StringListeners = new ArrayList<>();
    }
    
    public void addBytes( byte[] byteArray )
    {
        if ( null != byteArray )
        {
            final String auxString = new String( byteArray );
            notifyLineListeners( auxString );
        }
    }
    
    public void addListener( IStringListener listener )
    {
        if ( null != listener )
        {
            m_StringListeners.add( listener );
        }
    }
    
    private void notifyLineListeners( final String line )
    {
        System.out.println( line );
        for ( IStringListener listener : m_StringListeners  ) 
        {
            if ( null != listener )
            {
                listener.onString( line );
            }
        }         
    }
        
    private ArrayList<IStringListener> m_StringListeners;
}
